import Vue from "vue";
import Vuex from "vuex";
import createPersistedState from 'vuex-persistedstate'

Vue.use(Vuex)

const store=new Vuex.Store({
    state:{
        token:'' ,
        uid:'',
        date:''
    },
    mutations:{
      setData(state,data){
        state.date=data;
      },
      setToken(state,data){
         state.token=data;
        
      },
      setId(state,data){
        state.uid=data
      },
    
   
      //清除vuex保存到的数据
      mapClearState(state){
        for(let item in state){
          state[item]=''
        }
      },
    },
    
    //插件固定写法 默认是将mutations里的都存，现在做出制定
    plugins:[createPersistedState({
      reducer(val){
        return{
          token:val.passport,
         
        }
      }
    })]
    
    
})

export default store; 